# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.ods.tms.yl_tmsnew_branch_shipment_stop import jms_ods__yl_tmsnew_branch_shipment_stop
from jms.ods.tms.yl_tmsnew_tms_shipment_stop import jms_ods__yl_tmsnew_tms_shipment_stop
from jms.ods.tms.yl_tmsnew_branch_shipment import jms_ods__yl_tmsnew_branch_shipment
from jms.ods.tms.yl_tmsnew_tms_shipment import jms_ods__yl_tmsnew_tms_shipment
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator


jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt',
    email=['suning@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/tms/dwd_tmsnew_shipment_stop_union_base_dt/execute.hql',
    pool_slots=2,
    executor_cores=2,
    executor_memory='3G',
    num_executors=3,
    conf={'spark.dynamicAllocation.enabled'                  : 'true',
          'spark.shuffle.service.enabled'                    : 'true',
          #'spark.dynamicAllocation.maxExecutors'             : 15,
          'spark.dynamicAllocation.maxExecutors'             : 8,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 30,
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',
          'spark.executor.memoryOverhead'                    : '2G',
          'spark.sql.join.preferSortMergeJoin'               : 'false'
    },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 300,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 300,  # 最大分区
    },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=80),
    retries=2,
    sla=timedelta(hours=5),)

jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt << [
    jms_ods__yl_tmsnew_branch_shipment_stop,
    jms_ods__yl_tmsnew_tms_shipment_stop,
    jms_ods__yl_tmsnew_branch_shipment,
    jms_ods__yl_tmsnew_tms_shipment
]
